<template>
  <div class="v-identity">
    <!-- 饿了么组件 -->
  	<div class="title">{{ $t('message.writeIdentityInfo') }}</div>
  	<!--姓名-->
    <div class="label">{{ $t('message.personalIdentityName') }}:</div>
    <div class="input-group">
      <!--请填写姓名-->
      <input type="text" v-model="data.firstName" class="input input-short" :placeholder="this.$t('message.pleaseFillName')" />
      <!--请填写姓氏-->
      <input type="text" v-model="data.lastName" class="input input-short" :placeholder="this.$t('message.pleaseFillSurname')" />
    </div>
    <div class="error-tips" v-if="firstNameError">
      <!--请输入正确的名字-->
      {{$t('message.inputCorrectFirstName')}}
    </div>
    <div class="error-tips" v-if="lastNameError">
      <!--请输入正确的姓氏-->
      {{$t('message.inputCorrectLastName')}}
    </div>
    <!--性别-->
    <div class="label">{{ $t('message.personalIdentityGender') }}:</div>
    <div class="choose-group">
      <!--男性-->
      <div class="choose" :class="{ chooseActive: data.sex === 'male' }" @click="changeSex('male')">{{ $t('message.personalIdentityMale') }}</div>
      <!--女性-->
      <div class="choose" :class="{ chooseActive: data.sex === 'female' }" @click="changeSex('female')">{{ $t('message.personalIdentityFemale') }}</div>
    </div>
    <!--身份证号码-->
    <div class="label">{{ $t('message.personalIdentityIdentificationNumber') }}:</div>
    <!--请填写身份证号码-->
    <input type="text" v-model.trim="data.identityNumber" class="input input-long" :placeholder="this.$t('message.pleaseFillIdentificationNumberHolder')" />
    <div class="error-tips" v-if="identityNumberError">
      {{$t('message.pleaseFillCorrectIdNum')}}
    </div>
    <!--出生日期-->
    <div class="label">{{ $t('message.personalIdentityBirthday') }}:</div>
    <!--示例: 1900/12/31-->
    <!--<el-date-picker-->
      <!--v-model="data.birthDate"-->
      <!--type="date"-->
      <!--placeholder="选择日期"-->
      <!--format="dd/MM/yyyy"-->
      <!--:editable="false"-->
      <!--style="width:600px;margin-top:12px;">-->
    <!--</el-date-picker>-->
     <input type="text" onkeypress="return (event.keyCode>=48&&event.keyCode<=57) || (event.which>=48&&event.which<=57 || event.which === 8)" @keyup="filterVal('birthDate')" v-model="data.birthDate" class="input input-long" maxlength="10" :placeholder="`${this.$t('message.exampleHolder')}:1990/01/01(${this.$t('message.calendar')})`" />
    <div class="error-tips" v-if="birthDateError">
      {{$t('message.rightDate')}}
    </div>
    <!--身份证地址-->
    <div class="label">{{ $t('message.personalIdentityAddress') }}:</div>
    <!--请填写身份证地址-->
    <input type="text" v-model="data.identityAddress" class="input input-long" :placeholder="this.$t('message.pleaseFillIdentificationAddressHolder')" />
    <div class="error-tips" v-if="identityAddressError">
      {{$t('message.pleaseFillCorrectIdAddress')}}
    </div>
    <!--身份证有效期-->
    <div class="label">{{ $t('message.personalIdentityValidity') }}:</div>
    <div class="input-group">
      <!--<el-date-picker-->
        <!--v-model="data.endDate"-->
        <!--type="date"-->
        <!--placeholder="选择日期"-->
        <!--format="dd/MM/yyyy"-->
        <!--:editable="false"-->
        <!--style="width:600px;margin-top:12px;">-->
      <!--</el-date-picker>-->
      <!--<input type="text" onkeypress="return (event.keyCode>=48&&event.keyCode<=57) || (event.which>=48&&event.which<=57 || event.which === 8)" @keyup="filterVal('startDate')" v-model="data.startDate" class="input input-short" maxlength="10" :placeholder="`1990/12/31(${this.$t('message.calendar')})`" />-->
       <input type="text" onkeypress="return (event.keyCode>=48&&event.keyCode<=57) || (event.which>=48&&event.which<=57 || event.which === 8)" @keyup="filterVal('endDate')" v-model="data.endDate" class="input input-long" maxlength="10" :placeholder="`1990/06/01(${this.$t('message.calendar')})`" />
    </div>
    <!--<div class="error-tips" v-if="identityValidityError">-->
      <!--{{$t('message.pleaseFillCorrectIdValidity')}}-->
      <!--请输入正确的身份证有效期&#45;&#45;开始-->
      <!--{{ identityValidityStartTxt }}-->
    <!--</div>-->
    <div class="error-tips" v-if="identityValidityErrorEnd">
      <!--{{$t('message.pleaseFillCorrectIdValidity')}}-->
      <!--请输入正确的身份证有效期&#45;&#45;结束-->
      {{ identityValidityEndTxt }}
    </div>
    <!--现住地址-->
    <div class="label">{{ $t('message.personalIdentityAddressNow') }}:</div>
    <!--请填写现住地址-->
    <input type="text" v-model="data.currentAddress" class="input input-long" :placeholder="this.$t('message.pleaseFillAddressNowHolder')" />
    <div class="error-tips" v-if="currentAddressError">
      {{$t('message.rightLiveAddress')}}
    </div>
    <!--上传图片-->
    <div class="upload">
      <v-upload-image @uploadImage="upload('front', $event)" :image="data.frontOfIDCard">
        <!--请上传身份证正面照片 (或身份证复印件的签名照)-->
        <span slot="text">{{ $t('message.personalIdentityPleaseUploadIdentificationPicture') }}</span>
        <span slot="titleTip">({{ $t('message.PersonalIdentityAuthenticationOrIdentityCopy') }})</span>
        <!--身份证正面照片-->
        <img slot="photo" src="../../assets/images/register/identity_card_front.png" :alt="this.$t('message.identificationPicture')" />
      </v-upload-image>
    </div>
    <div class="error-tips" v-if="uploadImgError">
      {{$t('message.personalIdentityPleaseUploadIdentificationPicture')}}
    </div>
  </div>
</template>

<script>
import VUploadImage from '@/components/base/VUploadImage'
// import { setCookie } from '@/util/util'

export default {
  name: 'VIdentity',
  components: {
    VUploadImage
  },
  props: {
    parentData: {
      type: Object,
      default () {
        return {
          false: false,
          firstName: '',
          lastName: '',
          sex: 'male',
          identityNumber: '',
          birthDate: '',
          identityAddress: '',
          startDate: '',
          endDate: '',
          currentAddress: '',
          frontOfIDCard: ''
        }
      }
    }
  },
  data () {
    return {
      data: {
        firstName: this.parentData.firstName || '',
        lastName: this.parentData.lastName || '',
        sex: this.parentData.sex || 'male',
        identityNumber: this.parentData.identityNumber || '',
        birthDate: this.parentData.birthDate || '',
        identityAddress: this.parentData.identityAddress || '',
        //        startDate: this.parentData.startDate || '',
        endDate: this.parentData.endDate || '',
        currentAddress: this.parentData.currentAddress || '',
        frontOfIDCard: this.parentData.frontOfIDCard || ''
      },
      firstNameError: false,
      lastNameError: false,
      firstNameStatus: 0,
      lastNameStatus: 0,
      identityNumberError: false,
      identityNumberStatus: 0,
      identityAddressError: false,
      identityAddressStatus: 0,
      identityValidityError: false,
      identityValidityStartStatus: 0,
      identityValidityEndStatus: 0,
      birthDateError: false,
      birthDateStatus: 0,
      currentAddressError: false,
      currentAddressStatus: 0,
      uploadImgError: false,
      uploadImgStatus: 0,
      identityValidityErrorEnd: false
    }
  },
  computed: {
    /*identityValidityStartTxt () {
      2 '身份证开始有效期格式不正确'
      3 '身份证开始有效期不能小于出生日期'
      4 '身份证开始有效期不能大于身份证结束有效期'
      5 '请输入正确的身份证开始有效期'
      if (this.identityValidityStartStatus === 2) {
        return this.$t('message.identityStartFormatError')
      } else if (this.identityValidityStartStatus === 3) {
        return this.$t('message.identityStartNoLessBirthDate')
      } else if (this.identityValidityStartStatus === 4) {
        return this.$t('message.identityStartNoGreaterIdentityEnd')
      } else if (this.identityValidityStartStatus === 5) {
        return this.$t('message.inputRightIdentityStart')
      }
    },*/
    identityValidityEndTxt () {
      if (this.identityValidityEndStatus === 2) {
      //  return '身份证结束有效期格式不正确'
        return this.$t('message.identityEndFormatError')
      } else if (this.identityValidityEndStatus === 3) {
      //  return '身份证结束有效期不能小于身份证开始有效期'
        return this.$t('message.identityEndNoLessIdentityStart')
      } else if (this.identityValidityEndStatus === 4) {
      //  return '请输入正确的身份证结束有效期'
        return this.$t('message.inputRightIdentityEnd')
      }
    },
    isHandParent () {
      if (this.firstNameStatus === 1 && this.lastNameStatus === 1 && this.identityNumberStatus === 1 && this.identityAddressStatus === 1 && this.identityValidityEndStatus === 1 && this.birthDateStatus === 1 && this.currentAddressStatus === 1 && this.uploadImgStatus === 1) {
        return 'ok'
      } else {
        return 'no'
      }
    }
  },
  watch: {
    isHandParent (val) {
      if (val === 'ok') {
        this.$emit('change-params', this.data)
      } else if (val === 'no') {
        this.$emit('change-params', 'no')
      }
    },
    'data.firstName' (val) {
      clearTimeout(this.firstNameTimer)
      this.firstNameTimer = setTimeout(() => {
        if (/^\s*$/g.test(val)) {
          this.firstNameStatus = 2
          this.firstNameError = true
        } else {
          this.firstNameStatus = 1
          this.firstNameError = false
        }
      }, 900)
    },
    'data.lastName' (val) {
      clearTimeout(this.lastNameTimer)
      this.lastNameTimer = setTimeout(() => {
        if (/^\s*$/g.test(val)) {
          this.lastNameStatus = 2
          this.lastNameError = true
        } else {
          this.lastNameStatus = 1
          this.lastNameError = false
        }
      }, 900)
    },
    //  身份证号码验证
    'data.identityNumber' (val) {
      clearTimeout(this.identityNumberTimer)
      this.identityNumberTimer = setTimeout(() => {
        if (/(^\d{13}$)|(^\d{15}$)|(^\d{17}([0-9]|X)$)/g.test(val)) {
          this.identityNumberStatus = 1
          this.identityNumberError = false
        } else {
          this.identityNumberStatus = 2
          this.identityNumberError = true
        }
      }, 900)
    },
    //  身份证地址验证
    'data.identityAddress' (val) {
      clearTimeout(this.identityAddressTimer)
      this.identityAddressTimer = setTimeout(() => {
        if (/^\s*$/g.test(val)) {
          this.identityAddressStatus = 2
          this.identityAddressError = true
        } else {
          this.identityAddressStatus = 1
          this.identityAddressError = false
        }
      }, 900)
    },
    //  出生日期
    'data.birthDate' (newVal, oldVal) {
      if (newVal.length === 4) {
        if (newVal > oldVal) {
          newVal = newVal + '/'
          this.data.birthDate = newVal
        }
      } else if (newVal.length === 5) {
        if (newVal.charAt(4) !== '/') {
          if (newVal.charAt(4) !== '0' && newVal.charAt(4) !== '1') {
            newVal = newVal.substring(0, 4) + '/0' + newVal.charAt(4)
            this.data.birthDate = newVal
          } else {
            newVal = newVal.substring(0, 4) + '/' + newVal.charAt(4)
            this.data.birthDate = newVal
          }
        }
      } else if (newVal.length === 6) {
        if (newVal.charAt(5) !== '1' && newVal.charAt(5) !== '0') {
          if (newVal > oldVal) {
            newVal = newVal.substring(0, 5) + '0' + newVal.charAt(5) + '/'
            this.data.birthDate = newVal
          }
        }
      } else if (newVal.length === 7) {
        if (newVal.charAt(5) === '1') {
          if (parseInt(newVal.charAt(6)) > 2) {
            newVal = newVal.substring(0, 6)
            this.data.birthDate = newVal
          } else {
            if (newVal > oldVal) {
              newVal = newVal + '/'
              this.data.birthDate = newVal
            }
          }
        } else if (newVal.charAt(5) === '0') {
          if (newVal > oldVal) {
            newVal = newVal + '/'
            this.data.birthDate = newVal
          }
        }
      } else if (newVal.length === 8) {
        if (newVal.charAt(7) !== '/') {
          if (newVal.charAt(7) !== '0' && newVal.charAt(7) !== '1' && newVal.charAt(7) !== '2' && newVal.charAt(7) !== '3') {
            newVal = newVal.substring(0, 7) + '/0' + newVal.charAt(7)
            this.data.birthDate = newVal
          } else {
            newVal = newVal.substring(0, 7) + '/' + newVal.charAt(7)
            this.data.birthDate = newVal
          }
        }
      } else if (newVal.length === 9) {
        if (newVal.charAt(8) !== '1' && newVal.charAt(8) !== '2' && newVal.charAt(8) !== '3' && newVal.charAt(8) !== '0') {
          if (newVal > oldVal) {
            newVal = newVal.substring(0, 8) + '0' + newVal.charAt(8)
            this.data.birthDate = newVal
          }
        }
        if (newVal.substring(5, 7) === '02') {
          if (parseInt(newVal.charAt(8)) > 2) {
            newVal = newVal.substring(0, 8)
            this.data.birthDate = newVal
          }
        }
      } else if (newVal.length === 10) {
        if (newVal.substring(5, 7) === '01' || newVal.substring(5, 7) === '03' || newVal.substring(5, 7) === '05' || newVal.substring(5, 7) === '07' || newVal.substring(5, 7) === '08' || newVal.substring(5, 7) === '10' || newVal.substring(5, 7) === '12') {
          if (newVal.charAt(8) === '3') {
            if (parseInt(newVal.charAt(9)) > 1) {
              newVal = newVal.substring(0, 9)
              this.data.birthDate = newVal
              return
            }
          }
        } else if (newVal.substring(5, 7) === '04' || newVal.substring(5, 7) === '06' || newVal.substring(5, 7) === '09' || newVal.substring(5, 7) === '11') {
          if (newVal.charAt(8) === '3') {
            if (parseInt(newVal.charAt(9)) > 0) {
              newVal = newVal.substring(0, 9)
              this.data.birthDate = newVal
              return
            }
          }
        } else if (newVal.substring(5, 7) === '02') {
          if (parseInt(newVal.substring(0, 4)) % 4 === 0) {
            if (newVal.substring(2, 4) === '00') {
              if (parseInt(newVal.substring(0, 2)) % 4 !== 0) {
                if (newVal.charAt(9) === '9' && newVal.charAt(8) === '2') {
                  newVal = newVal.substring(0, 9)
                  this.data.birthDate = newVal
                  return
                }
              }
            }
          } else {
            if (newVal.charAt(9) === '9' && newVal.charAt(8) === '2') {
              newVal = newVal.substring(0, 9)
              this.data.birthDate = newVal
              return
            }
          }
        }
      }
      clearTimeout(this.birthDateTimer)
      this.birthDateTimer = setTimeout(() => {
        if (/^(\d{4})\/(\d{2})\/(\d{2})$/.test(newVal) && new Date(newVal).getTime() < new Date().getTime()) {
          this.birthDateStatus = 1
          this.birthDateError = false
        } else {
          this.birthDateStatus = 2
          this.birthDateError = true
        }
      }, 900)
//      clearTimeout(this.birthDateTimer)
//      this.birthDateTimer = setTimeout(() => {
//        if (newVal === null) {
//          this.birthDateStatus = 2
//          this.birthDateError = true
//        } else if (new Date(newVal).getTime() < new Date().getTime()) {
//          this.birthDateStatus = 1
//          this.birthDateError = false
//        } else {
//          this.birthDateStatus = 2
//          this.birthDateError = true
//        }
//      }, 900)
    },
    //  身份证有效期--开始
    /*'data.startDate' (newVal, oldVal) {
      clearTimeout(this.startDataTimer)
      this.startDataTimer = setTimeout(() => {
        if (/^(\d{4})\/(\d{2})\/(\d{2})$/.test(newVal)) {
          // 出生日期
          let birthDate = this.data.birthDate.split('/')
          // 身份证有效期结束
          let endData = this.data.endDate.split('/')
          let startDate = newVal.split('/')
          if (this.identityValidityEndStatus === 3) {
            this.identityValidityEndStatus = 1
            this.identityValidityErrorEnd = false
          }
          // 判断月份是否正确
          if (Number(startDate[1]) > 12) {
            this.identityValidityStartStatus = 5
            this.identityValidityError = true
            // 开始有效期跟出生日期对比
          } else if (Number(birthDate[0]) > Number(startDate[0]) || (Number(birthDate[0]) === Number(startDate[0]) && Number(birthDate[1]) > Number(startDate[1])) || (Number(birthDate[0]) === Number(startDate[0]) && Number(birthDate[1]) === Number(startDate[1]) && Number(birthDate[2]) > Number(startDate[2]))) {
            this.identityValidityStartStatus = 3
            this.identityValidityError = true
            // 判断结束日期是不是为空
          } else if (endData.length !== 1) {
            // 开始有效期跟结束日期对比
            if (Number(endData[0]) < Number(startDate[0]) || (Number(endData[0]) === Number(startDate[0]) && Number(endData[1]) < Number(startDate[1])) || (Number(endData[0]) === Number(startDate[0]) && Number(endData[1]) === Number(startDate[1]) && Number(endData[2]) < Number(startDate[2]))) {
              this.identityValidityStartStatus = 4
              this.identityValidityError = true
            } else {
              this.identityValidityStartStatus = 1
              this.identityValidityError = false
            }
          } else {
            this.identityValidityStartStatus = 1
            this.identityValidityError = false
          }
        } else {
          this.identityValidityStartStatus = 2
          this.identityValidityError = true
        }
      }, 900)
      if (newVal.length === 4) {
        if (newVal > oldVal) {
          newVal = newVal + '/'
          this.data.startDate = newVal
        }
      } else if (newVal.length === 5) {
        if (newVal.charAt(4) !== '/') {
          if (newVal.charAt(4) !== '0' && newVal.charAt(4) !== '1') {
            newVal = newVal.substring(0, 4) + '/0' + newVal.charAt(4)
            this.data.startDate = newVal
          } else {
            newVal = newVal.substring(0, 4) + '/' + newVal.charAt(4)
            this.data.startDate = newVal
          }
        }
      } else if (newVal.length === 6) {
        if (newVal.charAt(5) !== '1' && newVal.charAt(5) !== '0') {
          if (newVal > oldVal) {
            newVal = newVal.substring(0, 5) + '0' + newVal.charAt(5) + '/'
            this.data.startDate = newVal
          }
        }
      } else if (newVal.length === 7) {
        if (newVal.charAt(5) === '1') {
          if (parseInt(newVal.charAt(6)) > 2) {
            newVal = newVal.substring(0, 6)
            this.data.startDate = newVal
          } else {
            if (newVal > oldVal) {
              newVal = newVal + '/'
              this.data.startDate = newVal
            }
          }
        } else if (newVal.charAt(5) === '0') {
          if (newVal > oldVal) {
            newVal = newVal + '/'
            this.data.startDate = newVal
          }
        }
      } else if (newVal.length === 8) {
        if (newVal.charAt(7) !== '/') {
          if (newVal.charAt(7) !== '0' && newVal.charAt(7) !== '1' && newVal.charAt(7) !== '2' && newVal.charAt(7) !== '3') {
            newVal = newVal.substring(0, 7) + '/0' + newVal.charAt(7)
            this.data.startDate = newVal
          } else {
            newVal = newVal.substring(0, 7) + '/' + newVal.charAt(7)
            this.data.startDate = newVal
          }
        }
      } else if (newVal.length === 9) {
        if (newVal.charAt(8) !== '1' && newVal.charAt(8) !== '2' && newVal.charAt(8) !== '3' && newVal.charAt(8) !== '0') {
          if (newVal > oldVal) {
            newVal = newVal.substring(0, 8) + '0' + newVal.charAt(8)
            this.data.startDate = newVal
          }
        }
        if (newVal.substring(5, 7) === '02') {
          if (parseInt(newVal.charAt(8)) > 2) {
            newVal = newVal.substring(0, 8)
            this.data.startDate = newVal
          }
        }
      } else if (newVal.length === 10) {
        if (newVal.substring(5, 7) === '01' || newVal.substring(5, 7) === '03' || newVal.substring(5, 7) === '05' || newVal.substring(5, 7) === '07' || newVal.substring(5, 7) === '08' || newVal.substring(5, 7) === '10' || newVal.substring(5, 7) === '12') {
          if (newVal.charAt(8) === '3') {
            if (parseInt(newVal.charAt(9)) > 1) {
              newVal = newVal.substring(0, 9)
              this.data.startDate = newVal
              return
            }
          }
        } else if (newVal.substring(5, 7) === '04' || newVal.substring(5, 7) === '06' || newVal.substring(5, 7) === '09' || newVal.substring(5, 7) === '11') {
          if (newVal.charAt(8) === '3') {
            if (parseInt(newVal.charAt(9)) > 0) {
              newVal = newVal.substring(0, 9)
              this.data.startDate = newVal
              return
            }
          }
        } else if (newVal.substring(5, 7) === '02') {
          if (parseInt(newVal.substring(0, 4)) % 4 === 0) {
            if (newVal.substring(2, 4) === '00') {
              if (parseInt(newVal.substring(0, 2)) % 4 !== 0) {
                if (newVal.charAt(9) === '9' && newVal.charAt(8) === '2') {
                  newVal = newVal.substring(0, 9)
                  this.data.startDate = newVal
                  return
                }
              }
            }
          } else {
            if (newVal.charAt(9) === '9' && newVal.charAt(8) === '2') {
              newVal = newVal.substring(0, 9)
              this.data.startDate = newVal
              return
            }
          }
        }
      }
    },*/
    //  身份证有效期--结束
    'data.endDate' (newVal, oldVal) {
      clearTimeout(this.endDataTimer)
      this.endDataTimer = setTimeout(() => {
        if (/^(\d{4})\/(\d{2})\/(\d{2})$/.test(newVal) && new Date(newVal).getTime() + 86400000 >= new Date().getTime()) {
//        if (/^(\d{4})\/(\d{2})\/(\d{2})$/.test(newVal)) {
//          let endDate = newVal.split('/')
//          if (Number(endDate[1]) > 12 || Number(endDate[2]) > 31 || Number(endDate[2]) === 0) {
//            this.identityValidityEndStatus = 4
//            this.identityValidityErrorEnd = true
//          } else {
//            this.identityValidityEndStatus = 1
//            this.identityValidityErrorEnd = false
//          }
          this.identityValidityEndStatus = 1
          this.identityValidityErrorEnd = false
        } else {
          this.identityValidityEndStatus = 4
          this.identityValidityErrorEnd = true
        }
      }, 900)
      if (newVal.length === 4) {
        if (newVal > oldVal) {
          newVal = newVal + '/'
          this.data.endDate = newVal
        }
      } else if (newVal.length === 5) {
        if (newVal.charAt(4) !== '/') {
          if (newVal.charAt(4) !== '0' && newVal.charAt(4) !== '1') {
            newVal = newVal.substring(0, 4) + '/0' + newVal.charAt(4)
            this.data.endDate = newVal
          } else {
            newVal = newVal.substring(0, 4) + '/' + newVal.charAt(4)
            this.data.endDate = newVal
          }
        }
      } else if (newVal.length === 6) {
        if (newVal.charAt(5) !== '1' && newVal.charAt(5) !== '0') {
          if (newVal > oldVal) {
            newVal = newVal.substring(0, 5) + '0' + newVal.charAt(5) + '/'
            this.data.endDate = newVal
          }
        }
      } else if (newVal.length === 7) {
        if (newVal.charAt(5) === '1') {
          if (parseInt(newVal.charAt(6)) > 2) {
            newVal = newVal.substring(0, 6)
            this.data.endDate = newVal
            return
          } else {
            if (newVal > oldVal) {
              newVal = newVal + '/'
              this.data.endDate = newVal
            }
          }
        } else if (newVal.charAt(5) === '0') {
          if (newVal > oldVal) {
            newVal = newVal + '/'
            this.data.endDate = newVal
          }
        }
      } else if (newVal.length === 8) {
        if (newVal.charAt(7) !== '/') {
          if (newVal.charAt(7) !== '0' && newVal.charAt(7) !== '1' && newVal.charAt(7) !== '2' && newVal.charAt(7) !== '3') {
            newVal = newVal.substring(0, 7) + '/0' + newVal.charAt(7)
            this.data.endDate = newVal
          } else {
            newVal = newVal.substring(0, 7) + '/' + newVal.charAt(7)
            this.data.endDate = newVal
          }
        }
      } else if (newVal.length === 9) {
        if (newVal.charAt(8) !== '1' && newVal.charAt(8) !== '2' && newVal.charAt(8) !== '3' && newVal.charAt(8) !== '0') {
          if (newVal > oldVal) {
            newVal = newVal.substring(0, 8) + '0' + newVal.charAt(8)
            this.data.endDate = newVal
          }
        }
        if (newVal.substring(5, 7) === '02') {
          if (parseInt(newVal.charAt(8)) > 2) {
            newVal = newVal.substring(0, 8)
            this.data.endDate = newVal
          }
        }
      } else if (newVal.length === 10) {
        if (newVal.substring(5, 7) === '01' || newVal.substring(5, 7) === '03' || newVal.substring(5, 7) === '05' || newVal.substring(5, 7) === '07' || newVal.substring(5, 7) === '08' || newVal.substring(5, 7) === '10' || newVal.substring(5, 7) === '12') {
          if (newVal.charAt(8) === '3') {
            if (parseInt(newVal.charAt(9)) > 1) {
              newVal = newVal.substring(0, 9)
              this.data.endDate = newVal
              return
            }
          }
        } else if (newVal.substring(5, 7) === '04' || newVal.substring(5, 7) === '06' || newVal.substring(5, 7) === '09' || newVal.substring(5, 7) === '11') {
          if (newVal.charAt(8) === '3') {
            if (parseInt(newVal.charAt(9)) > 0) {
              newVal = newVal.substring(0, 9)
              this.data.endDate = newVal
              return
            }
          }
        } else if (newVal.substring(5, 7) === '02') {
          if (parseInt(newVal.substring(0, 4)) % 4 === 0) {
            if (newVal.substring(2, 4) === '00') {
              if (parseInt(newVal.substring(0, 2)) % 4 !== 0) {
                if (newVal.charAt(9) === '9' && newVal.charAt(8) === '2') {
                  newVal = newVal.substring(0, 9)
                  this.data.endDate = newVal
                  return
                }
              }
            }
          } else {
            if (newVal.charAt(9) === '9' && newVal.charAt(8) === '2') {
              newVal = newVal.substring(0, 9)
              this.data.endDate = newVal
              return
            }
          }
        }
      }
//      clearTimeout(this.endDataTimer)
//      this.endDataTimer = setTimeout(() => {
//        if (newVal === null) {
//          this.identityValidityEndStatus = 4
//          this.identityValidityErrorEnd = true
//        } else if (new Date(newVal).getTime() + 86400000 > new Date().getTime()) {
//          this.identityValidityEndStatus = 1
//          this.identityValidityErrorEnd = false
//        } else {
//          this.identityValidityEndStatus = 4
//          this.identityValidityErrorEnd = true
//        }
//      }, 900)
    },
    'data.currentAddress' (val) {
      clearTimeout(this.currentAddressTimer)
      this.currentAddressTimer = setTimeout(() => {
        if (/^\s*$/g.test(val)) {
          this.currentAddressStatus = 2
          this.currentAddressError = true
        } else {
          this.currentAddressStatus = 1
          this.currentAddressError = false
        }
      }, 900)
    },
    parentData (newVal) {
      this.data = newVal
    },
    data (val) {
      // 如果有传入的数据，初始化选中状态
      for (let key in val) {
        if (val[key] && val[key] !== '') {
          this[`${key}Status`] = 1
        }
      }
    }
  },
  methods: {
    filterVal (x) {
      this.data[x] = this.data[x].replace(/[^\d/]/g, '')
    },
    changeSex (str) {
      this.data.sex = str
    },
    upload (attr, val) {
      if (val) {
        this.uploadImgStatus = 1
        this.data[attr + 'OfIDCard'] = val
        this.uploadImgError = false
      } else {
        this.uploadImgStatus = 2
        this.data[attr + 'OfIDCard'] = val
        this.uploadImgError = true
      }
    }
  },
  mounted () {
    // 如果有传入的数据，初始化选中状态
    for (let key in this.data) {
      if (this.data[key] && this.data[key] !== '') {
        this[`${key}Status`] = 1
      }
    }
  }
}
</script>

<style scoped>
.title {
  line-height: 22px;
  font-size: 16px;
  font-weight: bold;
  padding-left: 18px;
  padding-bottom: 16px;
  position: relative;
}

.title:before {
  content: '';
  display: block;
  width: 4px;
  height: 15px;
  background-color: #ff600a;
  position: absolute;
  top: 4px;
  left: 0;
}

.label {
  line-height: 20px;
  margin-top: 24px;
}

.input {
  height: 48px;
  border: 1px solid #d7d7d7;
  border-radius: 2px;
  box-sizing: border-box;
  margin-top: 12px;
  padding: 0 15px;
}

.input-short {
  width: 288px;
  margin-right: 24px;
}

.input-short:last-child {
  margin-right: 0;
}

.choose-group {
  height: 48px;
  margin-top: 12px;
  overflow: hidden;
}

.choose {
  float: left;
  width: 158px;
  height: 46px;
  line-height: 46px;
  border: 1px solid #d7d7d7;
  border-radius: 2px;
  text-align: center;
  color: #a5a5a5;
  margin-right: 24px;
  cursor: pointer;
}

.choose:last-child {
  margin-right: 0;
}

.chooseActive {
  color: #333;
  border: 1px solid #ff600a;
  background: url(../../assets/images/icon_check.png) no-repeat right top;
}

.input-long {
  width: 600px;
}

.upload {
  margin-top: 60px;
}
</style>
